package com.boss.oss.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.io.IOException;
import java.util.concurrent.Executor;

/**
 * 多线程、读取配置
 * @author Hu_liantian
 * @date 2020/07/28
 */
public class ThreadUtil {

    @Bean
    public static OSS getOssClint(){

        String endpoint = new String();

        String accessKeyId = new String();

        String accessKeySecret = new String();

        try {
                endpoint = (String) ReadProperty.readProperty().get("endpoint");
                accessKeyId =(String) ReadProperty.readProperty().get("accessKeyId");
                accessKeySecret =(String) ReadProperty.readProperty().get("accessKeySecret");
            } catch (IOException e) {
                e.printStackTrace();
            }
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }

    @Bean("async")
    public Executor asyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(5);
        executor.setQueueCapacity(500);
        executor.setKeepAliveSeconds(60);
        executor.setThreadNamePrefix("我是线程-");
        executor.initialize();
        return executor;
    }

}
